package com.tledu.springboot19.controller;

import com.tledu.springboot19.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class NewsController {

    @Autowired
    private NewsService service;

    @RequestMapping("/news")
    public String news(String title, Model model) {
        if (title == null) {
            title = "";
        }
        // 按照栏目进行统计，统计新闻最多的7个栏目
        model.addAttribute("categoryCount", service.countCategory());
        // 按照时间进行统计，统计最近7天的新闻发布的数量变化的趋势
        model.addAttribute("dateCount", service.countByDate());
        model.addAttribute("list", service.search(title));
        return "news";
    }
}
